{extend name="template/base" /}
{block name="content"}
<div class="page-container">
    {include file="form" /}
    <div class="cl pd-5 bg-1 bk-gray">
        <span class="l">

        </span>
        <span class="r pt-5 pr-5">
            共有数据 ：<strong>{$count ?? '0'}</strong> 条
        </span>
    </div>

    <table class="table table-border table-bordered table-hover table-bg mt-20">
        <thead>
        <tr class="text-c">
            {include file="th" /}
            <th width="70">操作</th>
        </tr>
        </thead>
        <tbody>
        <?php use think\Db;?>
        {volist name="list" id="vo" key="k"}
        <tr class="text-c">
            {include file="td" /}
            <td>
                <a href="javascript:;" style="text-decoration: none" title="隐藏出行人员信息">
                    <i id="hide_info{$k}" class="Hui-iconfont" style="display: none; margin-left: 5px"
                       onclick="hide_info('{$k}','{$vo.order_id}')">&#xe699;</i>
                </a>
                <a href="javascript:;" style="text-decoration: none" title="显示出行人员信息">
                    <i id="show_info{$k}" class="Hui-iconfont" style="margin-left: 5px"
                       onclick="show_info('{$k}','{$vo.order_id}')">&#xe698;</i>
                </a>
            </td>
        </tr>
        <tr id="passenger_info{$k}" style="display: none">
            <!--<td></td>-->
            <td colspan="15">
                <form method="post" action="" id="traveler_info{$k}">
                    <table class="table table-border table-bordered table-hover table-bg">
                        <thead>
                        <tr class="text-c">
                            <th width="">姓名</th>
                            <th width="">证件类型</th>
                            <th width="">证件号码</th>
                            <th width="">年龄</th>
                            <th width="">性别</th>
                            <th width="">手机号码</th>
                            <th width="">保险金额</th>
                            <th width="">状态</th>
                        </tr>
                        </thead>
                        <tbody id="tbody{$k}">
                        {volist name="$vo.dispatch_traveler" id="traveler" key="traveler_key"}
                        <tr class="text-c">
                            <td>{$traveler.name}</td>
                            <td>身份证</td>
                            <td>{$traveler.id_card}</td>
                            <td>{$traveler.age}</td>
                            <td>{$traveler.sex}</td>
                            <td>{$traveler.phone}</td>
                            <td><input type="text" class="input-text" name="insurance_money[{$traveler.id}]" value="{$traveler.insurance_money}"/></td>
                            <td>{php}echo $traveler['is_error']===1?'异常':'正常'{/php}</td>
                        </tr>
                        {/volist}
                        </tbody>
                        <tr class="text-c">
                            <td colspan="8">
                                <!--<a id="export_traveler{$k}" href="javascript:;" onclick="export_traveler('{$k}','{$vo.id}')"-->
                                <!--class="label label-success radius" title="导出Excel">导出Excel</a>-->
                                <a id="save_traveler{$k}" href="javascript:;" onclick="save_traveler('{$k}','{$vo.id}')"
                                   class="label label-success radius" title="保存">保存</a>
                            </td>
                        </tr>
                    </table>
                </form>
            </td>
        </tr>
        {/volist}
        </tbody>
    </table>
    <div class="page-bootstrap">{$page ?? ''}</div>
</div>
{/block}
{block name="script"}

<script type="text/javascript" src="__LIB__/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="__LIB__/template/template.js"></script>
<script>
    var storage_idList = sessionStorage.getItem('idList')? sessionStorage.getItem('idList').split(',') : [];// 缓存中的id 列表
    var checkbox_list = [].slice.apply($('.check_box'));
    checkbox_list.map(function(element) {
        element.checked = false;
        for (var i = 0; i < storage_idList.length; i++) {
            if (element.value === storage_idList[i]) {
                element.checked = true;
            }
        }
    })

    $('html').on('click', '.check_box', function() {
        var id_list = [];    // 页面id列表
        var checked_id_list = [];       // 选中id列表
        var checked_checkbox_list = [].slice.apply($('.check_box:checked'));        // 页面选中项
        for (var i = 0; i < checkbox_list.length; i++) {
            id_list.push(checkbox_list[i].value);         // 页面所有项的ID列表
        }
        if (checked_checkbox_list.length > 0) {
            for (var i = 0; i < checked_checkbox_list.length; i++) {
                checked_id_list.push(checked_checkbox_list[i].value)            // 选中项的ID列表
            }
        }
        // 去除缓存中存在的页面项的ID
        for (var i = 0; i < storage_idList.length; i++) {
            for (var j = 0; j < id_list.length; j++) {
                if (storage_idList[i] === id_list[j]) {
                    storage_idList.splice(i, 1);
                    i--
                }
            }
        }
        // 将选中项的ID存进缓存ID列表中
        storage_idList = storage_idList.concat(checked_id_list);
        sessionStorage.setItem('idList', storage_idList);
    })

    // 保存出行人员信息
    function save_traveler(e, id) {
        var temp = $("#p_insurance_money"+e).val();
        var temp2 = $("#remark"+e).val();
        $.ajax({
            type: 'POST',
            url: "/admin/dispatch_insurance/save_traveler?id=" + id + "&p_insurance_money=" + temp + "&remark=" + temp2 ,
            data: $("#traveler_info" + e).serialize(),
            success: function (re) {
                if (re.msg) {
                    layer.msg(re.msg, {
                        time: 1000, //1s后自动关闭
                    }, function () {
                        //关闭后刷新
                        location.reload();
                    });
                }
            }
        });
    }

    // 隐藏人员信息
    function hide_info(e, order_id) {
        $('#show_info' + e).css('display', 'inline');
        $('#hide_info' + e).css('display', 'none');
        $('#passenger_info' + e).css('display', 'none');

    }

    // 显示人员信息
    function show_info(e, order_id) {
        $('#show_info' + e).css('display', 'none');
        $('#hide_info' + e).css('display', 'inline');
        $('#passenger_info' + e).css('display', 'table-row');
    }

    $(function () {
        $("[name='isrefund']").find("[value='{$Request.param.isrefund}']").attr("selected", true);
        $("[name='order_status']").find("[value='{$Request.param.order_status}']").attr("selected", true);
        $("[name='platform']").find("[value='{$Request.param.platform}']").attr("selected", true);
        $("[name='isallot']").find("[value='{$Request.param.isallot}']").attr("selected", true);
    })

    //全选
    $('#checkAlls').bind("click", function () {
        $("input[name='id[]']").prop("checked", this.checked);
        var sonChecked = $("input[name='id[]']").prop('checked');
        var allChecked = this.checked
        if (sonChecked && allChecked) {
            $('#xuan').css('display', 'inline-block') // 显示选择excel导出数据
            $('#sou').css('display', 'none') // 隐藏部分或全部excel导出数据
        } else {
            $('#xuan').css('display', 'none')
            $('#sou').css('display', 'inline-block')
        }
        // console.log('你点击我了')
        // console.log('你是否被选中', this.checked)
        // console.log('下级的选框', $("input[name='id[]']").prop('checked'))
    });

    // 单选
    $("input[name='id[]']").bind('click', function () {
        var radioData = $("input:checked[name='id[]']");
        // 选择数据的长度
        var len = radioData.serializeArray().length;
        if (len > 0) {
            $('#xuan').css('display', 'inline-block') // 显示选择excel导出数据
            $('#sou').css('display', 'none') // 隐藏部分或全部excel导出数据
        } else {
            $('#xuan').css('display', 'none')
            $('#sou').css('display', 'inline-block')
            $('#checkAlls').prop('checked', false); // 取消选择全选按钮
        }
        // console.log('你点击了单选')
        // console.log('点击的结果为：', this.checked)
        // console.log('你选择的数据是', radioData.serializeArray())
        // console.log('你选择的数据长度是',len)
    });

    function xuan() {
        var checkData = $("input:checked[name='id[]']");
        var dataArr = checkData.serializeArray();
        dataArr.push({name: 'search', value: 'all'})
        // console.log('选择的数据是', checkData.length)
        // console.log('选择的数据是', checkData.serializeArray())
        // console.log('选择的数组是', dataArr)
        $.ajax({
            type: 'post',
            url: '/admin/order/export_to_excel',
            data: dataArr,
            success: function (res) {
                if (res.code == 5) {
                    // console.log('data', res);
                    location.href = res.msg; // 下载文件
                    // 删除文件
                    unclinkFile(res.msg)
                    layer.msg('导出数据成功');
                } else {
                    layer_open('导出Excel数据', '/admin/pub/role/id/1')
                }
            }
        });
    }

    var value = 1;
    setTimeout(unclinkFile, 1200000, value); // 延迟20分钟1200000
    // 15分钟后删除文件-900000
    function unclinkFile(val) {

        setTimeout(function () {
            // 删除文件
            $.ajax({
                type: 'post',
                url: '/admin/order/del',
                data: {val: val},
                success: function (data) {

                    if (data.code != 5) {
                        console.log('删除失败', data.msg)
                    }
                }
            })
        }, 120000, val); // 2分钟后执行
    }
</script>

<script>
    function driverInfo(id) {
        var url = '/admin/driver/details';
        if (!id){
            layer.msg('缺少必要的参数');
        }
        $.ajax({
            type: 'get',
            url: url,
            data:{ id: id },
            success: function (data) {
                if (data.code == 1){
                    layer.msg(data.msg)
                    return false
                }else{
                    layer_open('详细资料','/admin/driver/details/id/'+id,{w:'1300px',h:'750px'})
                }
            }
        })
    }
</script>
{/block}
